package com.jming.yygh.common.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * MyBatisPlus配置类
 * @author jming
 * @date 2021-04-07
 */
@EnableTransactionManagement  // 事务处理
@Configuration
@MapperScan(basePackages = "com.jming.yygh.*.mapper")  // 映射扫描 当前项目下的所有mapper包
public class MybatisPlusConfig {

    /**
     * 分页查询
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        // 单页限制 500 条，小于 0 如 -1 不受限制
        return new PaginationInterceptor();

    }

    /**
     * 乐观锁配置
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }

}
